home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir24 / psi110g.zip / RSPFDUMP.C < prev    next >
C/C++ Source or Header  |  1994-04-17  |  4KB  |  125 lines

  1. #include "global.h"
  2. #ifdef RSPF
  3. #include "mbuf.h"
  4. #include "netuser.h"
  5. #include "internet.h"
  6. #include "socket.h"
  7. #include "ip.h"
  8. #include "rspf.h"
  9.   
  10. /* Dump an RSPF packet */
  11. void
  12. rspf_dump(fp,bpp,source,dest,check)
  13. FILE *fp;
  14. struct mbuf **bpp;
  15. int32 source,dest;
  16. int check;      /* If 0, bypass checksum verify */
  17. {
  18.     union rspf rspf;
  19.     struct pseudo_header ph;
  20.     int16 csum;
  21.     int sync;
  22.   
  23.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  24.         return;
  25.   
  26.     fprintf(fp,"RSPF: ");
  27.   
  28.     /* Compute checksum */
  29.     ph.source = source;
  30.     ph.dest = dest;
  31.     ph.protocol = RSPF_PTCL;
  32.     ph.length = len_p(*bpp);
  33.     if((csum = cksum(&ph,*bpp,ph.length)) == 0)
  34.         check = 0;  /* No checksum error */
  35.   
  36.     ntohrspf(&rspf,bpp);
  37.   
  38.     if(rspf.hdr.version != RSPF_VERSION)
  39.         fprintf(fp,"version %u ",rspf.hdr.version);
  40.     switch(rspf.hdr.type){
  41.         case RSPF_FULLPKT:
  42.             if(rspf.pkthdr.csum == 0)
  43.                 check = 0;
  44.             fprintf(fp,"type ROUTING UPDATE ");
  45.             if(rspf.pkthdr.fragtot != 1)
  46.                 fprintf(fp,"fragment %u frag total %u ",rspf.pkthdr.fragn,
  47.                 rspf.pkthdr.fragtot);
  48.             if(rspf.pkthdr.sync != 4)
  49.                 fprintf(fp,"sync %u ",rspf.pkthdr.sync);
  50.             fprintf(fp,"nodes %u id %u",rspf.pkthdr.nodes,rspf.pkthdr.envid);
  51.             if(check)
  52.                 fprintf(fp," CHECKSUM ERROR (%u)",csum);
  53.             fprintf(fp,"\n");
  54.             if(rspf.pkthdr.sync != 0)
  55.                 sync = rspf.pkthdr.sync - 4;
  56.             else
  57.                 sync = len_p(*bpp);
  58.             if(sync % 5 != 0){
  59.                 fprintf(fp,"      %d bytes\n",sync);
  60.                 pullup(bpp,NULLCHAR,sync);
  61.                 sync = 0;
  62.             }
  63.             rspfnodedump(fp,bpp,sync / 5);
  64.             break;
  65.         case RSPF_RRH:
  66.             if(rspf.rrh.csum == 0)
  67.                 check = 0;
  68.             fprintf(fp,"type RRH seq 0x%04x flags %d",rspf.rrh.seq,rspf.rrh.flags);
  69.             if(check)
  70.                 fprintf(fp," CHECKSUM ERROR (%u)",csum);
  71.             fprintf(fp,"\n");
  72.             break;
  73.         default:
  74.             fprintf(fp,"Unknown packet type\n");
  75.     }
  76. }
  77.   
  78. void
  79. rspfnodedump(fp,bpp,adjcnt)
  80. FILE *fp;       /* uses tputs() if NULLFILE */
  81. struct mbuf **bpp;  /* routing update without packet header */
  82. int adjcnt;     /* number of links before first node header */
  83. {
  84.     int c, links = 0;
  85.     char buf[128];
  86.     struct rspfnodeh nodeh;
  87.     struct rspflinkh linkh;
  88.     *buf = '\0';
  89.     for(;;) {
  90.         if(*buf != '\0') {
  91.             if(fp != NULLFILE)
  92.                 fprintf(fp,"%s",buf);
  93.             else
  94.                 tputs(buf);
  95.             *buf = '\0';
  96.         }
  97.         if(len_p(*bpp) == 0)
  98.             break;
  99.         if(adjcnt){
  100.             if((c = PULLCHAR(bpp)) == -1)
  101.                 break;
  102.             sprintf(buf,"            %s/%u\n",inet_ntoa(pull32(bpp)),c);
  103.             adjcnt--;
  104.             continue;
  105.         }
  106.         if(links){
  107.             if(ntohrspflink(&linkh,bpp) == -1)
  108.                 break;
  109.             sprintf(buf,"      horizon %u ERP factor %u cost %u adjacencies %u\n",
  110.             linkh.horizon,linkh.erp,linkh.cost,linkh.adjn);
  111.             adjcnt = linkh.adjn;
  112.             links--;
  113.             continue;
  114.         }
  115.         if(ntohrspfnode(&nodeh,bpp) == -1)
  116.             break;
  117.         sprintf(buf,"      Reporting Router: %s Seq %u Subseq %u links %u\n",
  118.         inet_ntoa(nodeh.addr),(int16)nodeh.seq,nodeh.subseq,
  119.         nodeh.links);
  120.         links = nodeh.links;
  121.     }
  122. }
  123. #endif /* RSPF */
  124.   
  125.